package com.tbs.parkingsaleapp.Http.Actionner;

import android.content.Context;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.tbs.parkingsaleapp.Http.IAsycHttpResultAction;
import com.tbs.parkingsaleapp.Http.JsonData.AdResult;
import com.tbs.parkingsaleapp.UI.LoginOrSign.Base.FaceLoginFragment;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;

public class ADResulter implements IAsycHttpResultAction<AdResult[]> {
    private AdResult[] ADS;
    private final Banner banner;

    public AdResult[] getADS()
    {
        return ADS;
    }
    public ADResulter(Banner banner)
    {
        this.banner=banner;
    }
    public static class myImgLoader extends com.youth.banner.loader.ImageLoader
    {

        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context).load((String) path).into(imageView);
        }
    }
    @Override
    public void ResultFunction(AdResult[] result) {
        ADS=result;
        ArrayList<String> imgs=new ArrayList<>();
        ArrayList<String> titles=new ArrayList<>();
        for (AdResult r:result
        ) {
            imgs.add(r.getImage());
            titles.add(r.getTitle());
        }

        banner.setImageLoader(new myImgLoader());
        banner.setImages(imgs);
        banner.setBannerTitles(titles);
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE);
        banner.setBannerAnimation(Transformer.DepthPage);
        banner.isAutoPlay(true);
        banner.setDelayTime(10000);
        banner.start();
    }
}
